from selenium import  webdriver
from time import sleep
from selenium.webdriver.common.by import By     #  元素定位
from selenium.webdriver.common.keys import Keys

# 打开浏览器
driver = webdriver.Edge()
# 窗口最大化
driver.maximize_window()
# 双击打开京东页面
driver.get('https://www.jd.com/')
# 常见定位元素的方法
# seatch1 = driver.find_element(By.TAG_NAME, 'input')
# seatch1 = driver.find_element(By.ID, 'key')
# seatch1 = driver.find_element(By.CLASS_NAME, 'text')
    # XPATH定位元素的4种方式
# seatch1 = driver.find_element(By.XPATH, '//*[@id="key"]')     # 相对定位
# seatch1 = driver.find_element(By.XPATH, '/html/body/div[1]/div[5]/div[1]/div[2]/div/div[2]/input')    # 绝对定位
# seatch1 = driver.find_element(By.XPATH, '//input[@id="key" and @class="text"]')   # 逻辑定位  and
# seatch1 = driver.find_element(By.XPATH, '//input[@id="key" or @class="text"]')   # 逻辑定位  or
# seatch1 = driver.find_element(By.CSS_SELECTOR, '#key')    # selector定位元素（id）
seatch1 = driver.find_element(By.CSS_SELECTOR, '.text')     # selector定位元素（class）
seatch1.send_keys("中性笔")
# seatch1.send_keys(Keys.ENTER)

sleep(10)




# # 关闭浏览器
# driver.quit()

